package com.yuniarti.konsultasikesehatan;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

public class KonsultasiActivity extends Activity {

	String id;
	DataParser jsonParser = new DataParser();
    EditText txt_konsultasi;
	Button btn_input;

    // url to create new register
    private static String input_konsultasi = "http://konsultasi-yakes.web.id/JSON/input-konsultasi.php";
	//private static String input_konsultasi = "http://10.0.2.2/adminweb/JSON/input-konsultasi.php";
    private static final String TAG_HASIL = "hasil";
    private static final String AR_ID = "id_member";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_konsultasi);

        Intent i = getIntent();
        id = i.getStringExtra(AR_ID);
        
        txt_konsultasi = (EditText) findViewById(R.id.txtKonsultasi);

        btn_input = (Button) findViewById(R.id.btn_kirim);
        btn_input.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View arg0) {
			
				String konsultasi = txt_konsultasi.getText().toString();

				List<NameValuePair> params = new ArrayList<NameValuePair>();

		            params.add(new BasicNameValuePair("id_member", id));
		            params.add(new BasicNameValuePair("konsultasi", konsultasi));
		 
		        JSONObject json = jsonParser.makeHttpRequest(input_konsultasi,"POST", params);
		         
		        
		            try {
		            	
		                int hasil = json.getInt(TAG_HASIL);
		 
		                if (hasil == 1) {
		                  
		                	Toast.makeText(KonsultasiActivity.this, "Input Berhasil YESSS!", Toast.LENGTH_SHORT).show();
		                //	txt_username.setText("Login Berhasil");
		                	
		                    Intent i = new Intent(getApplicationContext(), MenuMemberActivity.class);
		                    i.putExtra(AR_ID, id);
		                    startActivity(i);
		                    finish();
		                    
		                }
		                else {
		                	
		                	Toast.makeText(KonsultasiActivity.this, "Input Gagal!", Toast.LENGTH_SHORT).show();
		                //	txt_username.setText("Login Gagal");       
		                }
		            	
		                
		            } catch (JSONException e) {
		                e.printStackTrace();
		            }
				
			}
		});
    }
}
